package com.gsit.ocrbatch.utils;

import javax.mail.internet.MimeMessage;

import org.apache.log4j.Logger;
import org.springframework.mail.javamail.JavaMailSender;

import com.gsit.ocrbatch.domain.EmailMessage;

public class SendMailUtil implements Runnable{
	
	private Logger log= Logger.getLogger(SendMailUtil.class);

	private JavaMailSender mailSender;
	private MimeMessage message;
	private EmailMessage emailMessage;
	
	
	
	public SendMailUtil(EmailMessage emailMessage,JavaMailSender mailSender,MimeMessage message){
		this.emailMessage = emailMessage;
		this.mailSender = mailSender;
		this.message =message;
	}
	
	
	@Override
	public void run() {
	
		runEmail();
	
	}

	
	public void runEmail(){
		try {
			log.info("Email processing for "+message.getContent().toString());
			mailSender.send(message);
			//log.info("Email processing for "+emailMessageDTO.toString());
		} catch (Exception e) {
			//log.info("Error processing for "+emailMessageDTO.toString());
			//log.error("Error in \n"+emailMessageDTO.toString());
			log.error(e.getMessage(),e);
			e.printStackTrace();
		}
		
	}
}
